<h1>Listing tags</h1>

<table>
  <tr>
    <th>Name</th>
    <th>Description</th>
  </tr>
  <tr>
    <td><%= link_to 'New tag', new_tag_path %></th>
    <td>Create a new tag</td>
  </tr>

  <tr>
    <td>  </td>
    <td>  </td>
  </tr>

<% @tags.each do |tag| %>
  <tr>
    <% if logged_in? %>
      <% if Priv.find_by_user_id_and_tag_id(current_user.id,tag.id)%>
        <td><%= link_to "#{tag.name}", tag %></td>
        <td><%=h tag.description %></td>
        <td><%= link_to "Details", "#{ActionController::Base.relative_url_root}/tags/details/#{tag.id}" %></td>
        <% if Priv.find_by_user_id_and_tag_id(current_user.id,tag.id).is_owner%>
          <td><%= link_to 'Edit', edit_tag_path(tag) %></td>
	  <td><%= link_to 'Delete', tag, :confirm => 'Are you sure?', :method => :delete %></td>
        <% end %>                
        <% if Priv.find_by_user_id_and_tag_id(current_user.id,tag.id).can_harvest%>
          <td><%= link_to 'Harvest', tag, :confirm => 'Harvesting may take some time, are you sure you can wait?',:method => :harvest %></td>
        <% end %>   
      <% end %>
    <% else %>
      <td><%= link_to "#{tag.name}", tag %></td>
      <td><%=h tag.description %></td>
      <td><%= link_to "Details", "#{ActionController::Base.relative_url_root}/tags/details/#{tag.id}" %></td>
    <% end %>
  </tr>
<% end %>
<% @tags.each do |tag| %>
  <tr>
    <% if logged_in? %>
      <% if !Priv.find_by_user_id_and_tag_id(current_user.id,tag.id)%>
        <td><%= link_to "#{tag.name}", tag %></td>
        <td><%=h tag.description %></td>
        <td><%= link_to "Details", "#{ActionController::Base.relative_url_root}/tags/details/#{tag.id}" %></td>
      <% end %>
    <% end %>
  </tr>
<% end %>

</table>

<br />
